package com.dfec.water.service.impl;

import com.dfec.component.uid.core.service.UidService;
import com.dfec.framework.mybatis.core.page.PageParam;
import com.dfec.water.dao.YdbAreaImgDao;
import com.dfec.water.entity.YdbAreaImgEntity;
import com.dfec.water.param.AreaImgAddParam;
import com.dfec.water.service.YdbAreaImgService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dfec.framework.mybatis.core.page.PageUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author df
 * @title: YdbAreaImgServiceImpl
 * @description: 选择区域关联图片Service业务层处理
 * @date Mon Jan 20 16:55:01 CST 2025
 */
@Service("ydbAreaImgService")
@RequiredArgsConstructor
public class YdbAreaImgServiceImpl extends ServiceImpl<YdbAreaImgDao, YdbAreaImgEntity> implements YdbAreaImgService {

    private final YdbAreaImgDao ydbAreaImgDao;

    private final UidService uidService;

    /**
     * 分页查询
     *
     * @param pageParam 入参
     * @return PageUtils
     * @author df
     * @date Mon Jan 20 16:55:01 CST 2025
     */
    @Override
    public PageUtils queryPage(PageParam<YdbAreaImgEntity> pageParam) {
        return ydbAreaImgDao.selectPage(pageParam);
    }

    /**
     * 不带分页查询
     *
     * @param ydbAreaImgEntity 入参
     * @return List<YdbAreaImgEntity>
     * @author df
     * @date Mon Jan 20 16:55:01 CST 2025
     */
    @Override
    public List<YdbAreaImgEntity> listAll(YdbAreaImgEntity ydbAreaImgEntity) {
        return ydbAreaImgDao.selectAll(ydbAreaImgEntity);
    }



    @Override
    public void save(AreaImgAddParam param){
        ArrayList<YdbAreaImgEntity> ydbAreaImgEntities = new ArrayList<>();
        param.getImgList().forEach(item->{
            YdbAreaImgEntity ydbAreaImgEntity = new YdbAreaImgEntity();
            BeanUtils.copyProperties(item,ydbAreaImgEntity);
            ydbAreaImgEntity.setAreaId(param.getAreaId());
            ydbAreaImgEntity.setUploadTime(new Date());
            ydbAreaImgEntity.setId(uidService.next());
            ydbAreaImgEntities.add(ydbAreaImgEntity);
        });
        ydbAreaImgDao.insertBatch(ydbAreaImgEntities);
    }

    @Override
    public List<YdbAreaImgEntity> getImgList(Long areaId) {
            YdbAreaImgEntity ydbAreaImgEntity = new YdbAreaImgEntity();
            ydbAreaImgEntity.setAreaId(areaId);
            return ydbAreaImgDao.selectAll(ydbAreaImgEntity);
    }

}